package com.ysx.attendance;

import com.alibaba.fastjson.JSON;
import com.ysx.attendance.bean.ClassBean;
import com.ysx.attendance.bean.StudentBean;
import com.ysx.attendance.bean.TeacherBean;

import javax.servlet.GenericServlet;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.annotation.WebServlet;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@WebServlet(name="InitController",urlPatterns="/attendance/init")
public class InitController extends GenericServlet {


    @Override
    public void service(ServletRequest servletRequest, ServletResponse response) throws ServletException, IOException {

        // 1 找到校级管理 可以管理的班级  老师  学生

        // ?  数据设计放到后面


        ClassBean  houduan= new ClassBean();
        houduan.setClassId(20010);
        houduan.setClassName("后端班");

        StudentBean zhy= new StudentBean();
        zhy.setStudentId(10010);
        zhy.setStudentName("周海燕");
        zhy.setPhone("131 1294 6094");

        StudentBean fyh= new StudentBean();
        fyh.setStudentId(10020);
        fyh.setStudentName("方雅浩");
        fyh.setPhone("137 2839 1390");

        List<StudentBean> studentBeanList = new ArrayList<>();
        studentBeanList.add(zhy);
        studentBeanList.add(fyh);

        TeacherBean huang= new TeacherBean();
        huang.setTeacherId(30010);
        huang.setTeacherName("黄老师");

        houduan.setStudentBeanList(studentBeanList);
        houduan.setTeacherBean(huang);


        ClassBean  qianduan= new ClassBean();
        qianduan.setClassId(20020);
        qianduan.setClassName("前端班");

        StudentBean liang= new StudentBean();
        liang.setStudentId(10030);
        liang.setStudentName("梁俊升");
        liang.setPhone("131 1294 6095");

        StudentBean f= new StudentBean();
        f.setStudentId(10040);
        f.setStudentName("范浩宇");
        f.setPhone("137 2839 1395");

        List<StudentBean> studentBeanList1 = new ArrayList<>();
        studentBeanList1.add(liang);
        studentBeanList1.add(f);

        TeacherBean leng= new TeacherBean();
        leng.setTeacherId(30020);
        leng.setTeacherName("冷老师");

        qianduan.setStudentBeanList(studentBeanList1);
        qianduan.setTeacherBean(leng);




        List<ClassBean> classBeansList = new ArrayList<>();
        classBeansList.add(houduan);
        classBeansList.add(qianduan);

        Map<String,Object> map = new HashMap<>();
        map.put("code",200);
        map.put("message","success");
        map.put("classBeansList",classBeansList);

        String jsonString =  JSON.toJSONString(map);

        response.setContentType("text/html; charset=UTF-8");
        PrintWriter writer = response.getWriter();
        writer.print(jsonString);
        writer.flush();

    }
}
